package HLLib.control.HLButton;

import javax.microedition.lcdui.Image;

import HLLib.base.HLGraphics;
import HLLib.base.HLGraphics_H;
import HLLib.base.HLImage;
import HLLib.base.HLString;

public class HLButton extends HLIButton implements HLButton_H, HLGraphics_H {

    public String text;

    public byte fontSize = FONT_SIZE_SMALL;

    public int textColor = 0xffffff;

    public int textShadowColor;

    public int textStyle;

    public int textPosStyle = HCENTER_VCENTER;

    public int backColor = 0xff00ff;

    public int rimColor = 0xff00ff;

    public boolean haveBorder;

    public int timer;

    public int stopBackColor = 0xff448ff8;

    public int stopTextColor = 0xffffffff;

    Image icon;

    public HLButton() {
    }

    public HLButton(String chars) {
        this.type = TYPE_UNKNOWN;
        text = chars;
        width = (short) HLGraphics.StringWidth1(chars);
        height = (short) HLGraphics.StringHeight();
    }

    public HLButton(HLImage icon) {
        this.icon = icon.image;
        width = icon.GetWidth();
        height = icon.GetHeight();
    }

    public HLButton(String chars, Image icon) {
        this(chars);
        this.icon = icon;
        width = width + icon.getWidth() + 6;
        height = Math.max(height, icon.getHeight());
    }

    public void SetTextIcon(String chars) {
        text = chars;
        width = (short) HLGraphics.StringWidth1(chars);
        height = (short) HLGraphics.StringHeight();
        width = width + icon.getWidth() + 6;
        height = Math.max(height, icon.getHeight());
    }

    public HLButton(int type, String chars) {
        this(chars);
        this.type = (byte) type;
    }

    public void Render(HLGraphics g) {
        int screenX = GetScreenX();
        int screenY = GetScreenY();
        int textColor = this.textColor;
        int backColor = this.backColor;
        if (icon != null) {
            g.DrawImageAdjustable(new HLImage(icon), screenX, screenY, width, height, HLGraphics.TRANS_NONE, LEFT_VCENTER);
        }

        if (tabelStop && IsFocus()) {
            textColor = stopTextColor;
            backColor = stopBackColor;
        }

        if (backColor != 0xff00ff) {
            if (icon != null) {
                g.FillRect(screenX + icon.getWidth() + 2, screenY, width - icon.getWidth(), height, backColor);
            } else {
                g.FillRect(screenX, screenY, width, height, backColor);
            }

        }
        if (rimColor != 0xff00ff) {
            g.DrawRectRim(screenX, screenY, width, height, 1, rimColor);
        }
        int oldFontSize = HLGraphics.GetFontSize();
        if (icon != null) {

            if (text != null) {
                g.DrawStringAdjustable(new HLString(text), textColor, textShadowColor, screenX + icon.getWidth() + 4, screenY, width, height, textStyle, LEFT_VCENTER);
            }
        } else {
            if (text != null) {
                g.DrawStringAdjustable(new HLString(text), textColor, textShadowColor, screenX, screenY, width, height, textStyle, textPosStyle);
            }
        }

        if (haveBorder) {
            // HLFrame.Render(g, screenX, screenY, width, height);
        }
        // if(tabelStop) {
        // if(IsFocus()) {
        // g.DrawRectRim( screenX, screenY, width, height, 1, 0xffffffff);
        // }
        // }
    }

    public void Refresh() {

    }

    public void UnLoad() {
    }

}
